package org.deadline.service.config;

import java.util.List;
import org.deadline.model.config.Role;
import org.deadline.repository.config.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class RoleServiceImpl implements RoleService {

	@Autowired
    RoleRepository roleRepository;

	public long countAllRoles() {
        return roleRepository.count();
    }

	public void deleteRole(Role role) {
        roleRepository.delete(role);
    }

	public Role findRole(Long id) {
        return roleRepository.findOne(id);
    }

	public List<Role> findAllRoles() {
        return roleRepository.findAll();
    }

	public List<Role> findRoleEntries(int firstResult, int maxResults) {
        return roleRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void saveRole(Role role) {
        roleRepository.save(role);
    }

	public Role updateRole(Role role) {
        return roleRepository.save(role);
    }
}
